{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "bc8364f2",
   "metadata": {
    "hide_input": true,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: pyecharts in c:\\users\\1\\anaconda3\\lib\\site-packages (2.0.8)\n",
      "Requirement already satisfied: jinja2 in c:\\users\\1\\anaconda3\\lib\\site-packages (from pyecharts) (3.1.6)\n",
      "Requirement already satisfied: prettytable in c:\\users\\1\\anaconda3\\lib\\site-packages (from pyecharts) (3.16.0)\n",
      "Requirement already satisfied: simplejson in c:\\users\\1\\anaconda3\\lib\\site-packages (from pyecharts) (3.20.1)\n",
      "Requirement already satisfied: MarkupSafe>=2.0 in c:\\users\\1\\anaconda3\\lib\\site-packages (from jinja2->pyecharts) (2.0.1)\n",
      "Requirement already satisfied: wcwidth in c:\\users\\1\\anaconda3\\lib\\site-packages (from prettytable->pyecharts) (0.2.5)\n"
     ]
    }
   ],
   "source": [
    "!pip install pyecharts\n",
    "import pandas as pd\n",
    "import pyecharts \n",
    "from IPython.display import HTML"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "8f9fb48e-0006-4ad3-8660-735dca7d727a",
   "metadata": {},
   "outputs": [],
   "source": [
    "c=pd.read_excel(r\"E:\\123.xlsx\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "e0a461e1",
   "metadata": {
    "hide_input": true
   },
   "outputs": [],
   "source": [
    "yg = c[(c['商品编码(平台)'] == 10000193076155) | (c['商品编码(平台)'] == 10000220846590)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "c6142f19",
   "metadata": {
    "hide_input": false
   },
   "outputs": [],
   "source": [
    "cj = yg[yg['商品发货'] == '已发货']\n",
    "cj2=yg[yg['支付时间'] != '-']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "3b96032a",
   "metadata": {
    "hide_input": true
   },
   "outputs": [],
   "source": [
    "#成交chengjiao(含发货后退款)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2a3c5b22",
   "metadata": {},
   "source": [
    "# 这里的未发货指下单未付款，和下单后在发货前退款的总和"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "54a78f18",
   "metadata": {
    "hide_input": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "已发货    432\n",
      "未发货    108\n",
      "Name: 商品发货, dtype: int64\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<!DOCTYPE html>\n",
       "<html>\n",
       "<head>\n",
       "    <meta charset=\"UTF-8\">\n",
       "    <title>Awesome-pyecharts</title>\n",
       "                <script type=\"text/javascript\" src=\"https://assets.pyecharts.org/assets/v5/echarts.min.js\"></script>\n",
       "\n",
       "    \n",
       "</head>\n",
       "<body >\n",
       "    <div id=\"04b2a40dea654278bd5f5dcbbd10b671\" class=\"chart-container\" style=\"width:900px; height:500px; \"></div>\n",
       "    <script>\n",
       "        var chart_04b2a40dea654278bd5f5dcbbd10b671 = echarts.init(\n",
       "            document.getElementById('04b2a40dea654278bd5f5dcbbd10b671'), 'white', {renderer: 'canvas'});\n",
       "        var option_04b2a40dea654278bd5f5dcbbd10b671 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"aria\": {\n",
       "        \"enabled\": false\n",
       "    },\n",
       "    \"color\": [\n",
       "        \"#5470c6\",\n",
       "        \"#91cc75\",\n",
       "        \"#fac858\",\n",
       "        \"#ee6666\",\n",
       "        \"#73c0de\",\n",
       "        \"#3ba272\",\n",
       "        \"#fc8452\",\n",
       "        \"#9a60b4\",\n",
       "        \"#ea7ccc\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"pie\",\n",
       "            \"name\": \"\\u5546\\u54c1\\u53d1\\u8d27\\u72b6\\u6001\\u5360\\u6bd4\",\n",
       "            \"colorBy\": \"data\",\n",
       "            \"legendHoverLink\": true,\n",
       "            \"selectedMode\": false,\n",
       "            \"selectedOffset\": 10,\n",
       "            \"clockwise\": true,\n",
       "            \"startAngle\": 90,\n",
       "            \"minAngle\": 0,\n",
       "            \"minShowLabelAngle\": 0,\n",
       "            \"avoidLabelOverlap\": true,\n",
       "            \"stillShowZeroSum\": true,\n",
       "            \"percentPrecision\": 2,\n",
       "            \"showEmptyCircle\": true,\n",
       "            \"emptyCircleStyle\": {\n",
       "                \"color\": \"lightgray\",\n",
       "                \"borderColor\": \"#000\",\n",
       "                \"borderWidth\": 0,\n",
       "                \"borderType\": \"solid\",\n",
       "                \"borderDashOffset\": 0,\n",
       "                \"borderCap\": \"butt\",\n",
       "                \"borderJoin\": \"bevel\",\n",
       "                \"borderMiterLimit\": 10,\n",
       "                \"opacity\": 1\n",
       "            },\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u5df2\\u53d1\\u8d27\",\n",
       "                    \"value\": 0.8\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u53d1\\u8d27\\u524d\\u9000\\u6b3e\",\n",
       "                    \"value\": 0.08888888888888889\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u4ed8\\u6b3e\\u524d\\u9000\\u6b3e\",\n",
       "                    \"value\": 0.1111111111111111\n",
       "                }\n",
       "            ],\n",
       "            \"radius\": [\n",
       "                \"0%\",\n",
       "                \"75%\"\n",
       "            ],\n",
       "            \"center\": [\n",
       "                \"50%\",\n",
       "                \"50%\"\n",
       "            ],\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"margin\": 8,\n",
       "                \"formatter\": \"{b}: {d}%\",\n",
       "                \"valueAnimation\": false\n",
       "            },\n",
       "            \"labelLine\": {\n",
       "                \"show\": true,\n",
       "                \"showAbove\": false,\n",
       "                \"length\": 15,\n",
       "                \"length2\": 15,\n",
       "                \"smooth\": false,\n",
       "                \"minTurnAngle\": 90,\n",
       "                \"maxSurfaceAngle\": 90\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u5df2\\u53d1\\u8d27\",\n",
       "                \"\\u53d1\\u8d27\\u524d\\u9000\\u6b3e\",\n",
       "                \"\\u4ed8\\u6b3e\\u524d\\u9000\\u6b3e\"\n",
       "            ],\n",
       "            \"selected\": {},\n",
       "            \"show\": true,\n",
       "            \"left\": \"2%\",\n",
       "            \"top\": \"15%\",\n",
       "            \"orient\": \"vertical\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14,\n",
       "            \"backgroundColor\": \"transparent\",\n",
       "            \"borderColor\": \"#ccc\",\n",
       "            \"borderRadius\": 0,\n",
       "            \"pageButtonItemGap\": 5,\n",
       "            \"pageButtonPosition\": \"end\",\n",
       "            \"pageFormatter\": \"{current}/{total}\",\n",
       "            \"pageIconColor\": \"#2f4554\",\n",
       "            \"pageIconInactiveColor\": \"#aaa\",\n",
       "            \"pageIconSize\": 15,\n",
       "            \"animationDurationUpdate\": 800,\n",
       "            \"selector\": false,\n",
       "            \"selectorPosition\": \"auto\",\n",
       "            \"selectorItemGap\": 7,\n",
       "            \"selectorButtonGap\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"enterable\": false,\n",
       "        \"confine\": false,\n",
       "        \"appendToBody\": false,\n",
       "        \"transitionDuration\": 0.4,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5,\n",
       "        \"order\": \"seriesAsc\"\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"text\": \"\\u5546\\u54c1\\u53d1\\u8d27\\u72b6\\u6001\\u5360\\u6bd4\\u997c\\u56fe\",\n",
       "            \"target\": \"blank\",\n",
       "            \"subtarget\": \"blank\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"textAlign\": \"auto\",\n",
       "            \"textVerticalAlign\": \"auto\",\n",
       "            \"triggerEvent\": false\n",
       "        }\n",
       "    ],\n",
       "    \"toolbox\": {\n",
       "        \"show\": true,\n",
       "        \"orient\": \"horizontal\",\n",
       "        \"itemSize\": 15,\n",
       "        \"itemGap\": 10,\n",
       "        \"left\": \"80%\",\n",
       "        \"feature\": {\n",
       "            \"saveAsImage\": {\n",
       "                \"type\": \"png\",\n",
       "                \"backgroundColor\": \"auto\",\n",
       "                \"connectedBackgroundColor\": \"#fff\",\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u4fdd\\u5b58\\u4e3a\\u56fe\\u7247\",\n",
       "                \"pixelRatio\": 1\n",
       "            },\n",
       "            \"restore\": {\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u8fd8\\u539f\"\n",
       "            },\n",
       "            \"dataView\": {\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u6570\\u636e\\u89c6\\u56fe\",\n",
       "                \"readOnly\": false,\n",
       "                \"lang\": [\n",
       "                    \"\\u6570\\u636e\\u89c6\\u56fe\",\n",
       "                    \"\\u5173\\u95ed\",\n",
       "                    \"\\u5237\\u65b0\"\n",
       "                ],\n",
       "                \"backgroundColor\": \"#fff\",\n",
       "                \"textareaColor\": \"#fff\",\n",
       "                \"textareaBorderColor\": \"#333\",\n",
       "                \"textColor\": \"#000\",\n",
       "                \"buttonColor\": \"#c23531\",\n",
       "                \"buttonTextColor\": \"#fff\"\n",
       "            },\n",
       "            \"dataZoom\": {\n",
       "                \"show\": true,\n",
       "                \"title\": {\n",
       "                    \"zoom\": \"\\u533a\\u57df\\u7f29\\u653e\",\n",
       "                    \"back\": \"\\u533a\\u57df\\u7f29\\u653e\\u8fd8\\u539f\"\n",
       "                },\n",
       "                \"icon\": {},\n",
       "                \"filterMode\": \"filter\"\n",
       "            },\n",
       "            \"magicType\": {\n",
       "                \"show\": true,\n",
       "                \"type\": [\n",
       "                    \"line\",\n",
       "                    \"bar\",\n",
       "                    \"stack\",\n",
       "                    \"tiled\"\n",
       "                ],\n",
       "                \"title\": {\n",
       "                    \"line\": \"\\u5207\\u6362\\u4e3a\\u6298\\u7ebf\\u56fe\",\n",
       "                    \"bar\": \"\\u5207\\u6362\\u4e3a\\u67f1\\u72b6\\u56fe\",\n",
       "                    \"stack\": \"\\u5207\\u6362\\u4e3a\\u5806\\u53e0\",\n",
       "                    \"tiled\": \"\\u5207\\u6362\\u4e3a\\u5e73\\u94fa\"\n",
       "                },\n",
       "                \"icon\": {}\n",
       "            }\n",
       "        }\n",
       "    }\n",
       "};\n",
       "        chart_04b2a40dea654278bd5f5dcbbd10b671.setOption(option_04b2a40dea654278bd5f5dcbbd10b671);\n",
       "    </script>\n",
       "</body>\n",
       "</html>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cj=yg[yg['商品发货']=='已发货']\n",
    "cjw=yg[yg['商品发货']=='未发货']\n",
    "print(yg['商品发货'].value_counts())\n",
    "import pandas as pd\n",
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Pie\n",
    "\n",
    "# 假设 yg 是你的 DataFrame，这里模拟生成示例数据\n",
    "\n",
    "\n",
    "# 筛选已发货和未发货的数据\n",
    "cj = yg[yg['商品发货'] == '已发货']\n",
    "cjw = yg[(yg['商品发货'] == '未发货') & (yg['支付时间'] != '-')]\n",
    "cj1=yg[(yg['商品发货'] == '未发货') & (yg['支付时间'] == '-')]\n",
    "# 计算已发货和未发货的数量\n",
    "shipped_count = len(cj)\n",
    "unshipped_count = len(cjw)\n",
    "fhq=len(cj1)\n",
    "# 计算占比\n",
    "total_count = shipped_count + unshipped_count+fhq\n",
    "shipped_ratio = shipped_count / total_count\n",
    "unshipped_ratio = unshipped_count / total_count\n",
    "fhq_ratio=fhq / total_count\n",
    "# 准备数据用于绘制饼图\n",
    "labels = ['已发货', '发货前退款','付款前退款']\n",
    "values = [shipped_ratio, unshipped_ratio,fhq_ratio]\n",
    "\n",
    "# 创建饼图\n",
    "pie = (\n",
    "    Pie()\n",
    "    .add(\n",
    "        series_name=\"商品发货状态占比\",\n",
    "        data_pair=[list(z) for z in zip(labels, values)],\n",
    "        radius=[\"0%\", \"75%\"],\n",
    "    )\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title=\"商品发货状态占比饼图\"),\n",
    "        legend_opts=opts.LegendOpts(orient=\"vertical\", pos_top=\"15%\", pos_left=\"2%\"),\n",
    "        toolbox_opts=opts.ToolboxOpts(is_show=True)\n",
    "    )\n",
    "    .set_series_opts(\n",
    "        label_opts=opts.LabelOpts(formatter=\"{b}: {d}%\")\n",
    "    )\n",
    ")\n",
    "\n",
    "# 渲染图表\n",
    "pie.render_notebook()\n",
    "\n",
    "# 生成 HTML 代码\n",
    "html = pie.render_embed()\n",
    "\n",
    "# 在 Notebook 中显示\n",
    "HTML(html)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9adbbfcd",
   "metadata": {},
   "source": [
    "# 这里的指的是成交后的，就是付过款的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "id": "db5bbf0b",
   "metadata": {
    "hide_input": true,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "已发货    432\n",
      "未发货    108\n",
      "Name: 商品发货, dtype: int64\n",
      "售前+售后退款率12.292%\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<!DOCTYPE html>\n",
       "<html>\n",
       "<head>\n",
       "    <meta charset=\"UTF-8\">\n",
       "    <title>Awesome-pyecharts</title>\n",
       "                <script type=\"text/javascript\" src=\"https://assets.pyecharts.org/assets/v5/echarts.min.js\"></script>\n",
       "\n",
       "    \n",
       "</head>\n",
       "<body >\n",
       "    <div id=\"8ac4bf72536f43bea258913573bc2c5d\" class=\"chart-container\" style=\"width:900px; height:500px; \"></div>\n",
       "    <script>\n",
       "        var chart_8ac4bf72536f43bea258913573bc2c5d = echarts.init(\n",
       "            document.getElementById('8ac4bf72536f43bea258913573bc2c5d'), 'white', {renderer: 'canvas'});\n",
       "        var option_8ac4bf72536f43bea258913573bc2c5d = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"aria\": {\n",
       "        \"enabled\": false\n",
       "    },\n",
       "    \"color\": [\n",
       "        \"#5470c6\",\n",
       "        \"#91cc75\",\n",
       "        \"#fac858\",\n",
       "        \"#ee6666\",\n",
       "        \"#73c0de\",\n",
       "        \"#3ba272\",\n",
       "        \"#fc8452\",\n",
       "        \"#9a60b4\",\n",
       "        \"#ea7ccc\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"pie\",\n",
       "            \"name\": \"\\u5546\\u54c1\\u53d1\\u8d27\\u72b6\\u6001\\u5360\\u6bd4\",\n",
       "            \"colorBy\": \"data\",\n",
       "            \"legendHoverLink\": true,\n",
       "            \"selectedMode\": false,\n",
       "            \"selectedOffset\": 10,\n",
       "            \"clockwise\": true,\n",
       "            \"startAngle\": 90,\n",
       "            \"minAngle\": 0,\n",
       "            \"minShowLabelAngle\": 0,\n",
       "            \"avoidLabelOverlap\": true,\n",
       "            \"stillShowZeroSum\": true,\n",
       "            \"percentPrecision\": 2,\n",
       "            \"showEmptyCircle\": true,\n",
       "            \"emptyCircleStyle\": {\n",
       "                \"color\": \"lightgray\",\n",
       "                \"borderColor\": \"#000\",\n",
       "                \"borderWidth\": 0,\n",
       "                \"borderType\": \"solid\",\n",
       "                \"borderDashOffset\": 0,\n",
       "                \"borderCap\": \"butt\",\n",
       "                \"borderJoin\": \"bevel\",\n",
       "                \"borderMiterLimit\": 10,\n",
       "                \"opacity\": 1\n",
       "            },\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u5df2\\u53d1\\u8d27\",\n",
       "                    \"value\": 0.8770833333333333\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u552e\\u524d\\u9000\\u6b3e\",\n",
       "                    \"value\": 0.1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u552e\\u540e\\u9000\\u6b3e\",\n",
       "                    \"value\": 0.022916666666666665\n",
       "                }\n",
       "            ],\n",
       "            \"radius\": [\n",
       "                \"0%\",\n",
       "                \"75%\"\n",
       "            ],\n",
       "            \"center\": [\n",
       "                \"50%\",\n",
       "                \"50%\"\n",
       "            ],\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"margin\": 8,\n",
       "                \"formatter\": \"{b}: {d}%\",\n",
       "                \"valueAnimation\": false\n",
       "            },\n",
       "            \"labelLine\": {\n",
       "                \"show\": true,\n",
       "                \"showAbove\": false,\n",
       "                \"length\": 15,\n",
       "                \"length2\": 15,\n",
       "                \"smooth\": false,\n",
       "                \"minTurnAngle\": 90,\n",
       "                \"maxSurfaceAngle\": 90\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u5df2\\u53d1\\u8d27\",\n",
       "                \"\\u552e\\u524d\\u9000\\u6b3e\",\n",
       "                \"\\u552e\\u540e\\u9000\\u6b3e\"\n",
       "            ],\n",
       "            \"selected\": {},\n",
       "            \"show\": true,\n",
       "            \"left\": \"2%\",\n",
       "            \"top\": \"15%\",\n",
       "            \"orient\": \"vertical\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14,\n",
       "            \"backgroundColor\": \"transparent\",\n",
       "            \"borderColor\": \"#ccc\",\n",
       "            \"borderRadius\": 0,\n",
       "            \"pageButtonItemGap\": 5,\n",
       "            \"pageButtonPosition\": \"end\",\n",
       "            \"pageFormatter\": \"{current}/{total}\",\n",
       "            \"pageIconColor\": \"#2f4554\",\n",
       "            \"pageIconInactiveColor\": \"#aaa\",\n",
       "            \"pageIconSize\": 15,\n",
       "            \"animationDurationUpdate\": 800,\n",
       "            \"selector\": false,\n",
       "            \"selectorPosition\": \"auto\",\n",
       "            \"selectorItemGap\": 7,\n",
       "            \"selectorButtonGap\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"enterable\": false,\n",
       "        \"confine\": false,\n",
       "        \"appendToBody\": false,\n",
       "        \"transitionDuration\": 0.4,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5,\n",
       "        \"order\": \"seriesAsc\"\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"text\": \"\\u5546\\u54c1\\u53d1\\u8d27\\u72b6\\u6001\\u5360\\u6bd4\\u997c\\u56fe\",\n",
       "            \"target\": \"blank\",\n",
       "            \"subtarget\": \"blank\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"textAlign\": \"auto\",\n",
       "            \"textVerticalAlign\": \"auto\",\n",
       "            \"triggerEvent\": false\n",
       "        }\n",
       "    ],\n",
       "    \"toolbox\": {\n",
       "        \"show\": true,\n",
       "        \"orient\": \"horizontal\",\n",
       "        \"itemSize\": 15,\n",
       "        \"itemGap\": 10,\n",
       "        \"left\": \"80%\",\n",
       "        \"feature\": {\n",
       "            \"saveAsImage\": {\n",
       "                \"type\": \"png\",\n",
       "                \"backgroundColor\": \"auto\",\n",
       "                \"connectedBackgroundColor\": \"#fff\",\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u4fdd\\u5b58\\u4e3a\\u56fe\\u7247\",\n",
       "                \"pixelRatio\": 1\n",
       "            },\n",
       "            \"restore\": {\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u8fd8\\u539f\"\n",
       "            },\n",
       "            \"dataView\": {\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u6570\\u636e\\u89c6\\u56fe\",\n",
       "                \"readOnly\": false,\n",
       "                \"lang\": [\n",
       "                    \"\\u6570\\u636e\\u89c6\\u56fe\",\n",
       "                    \"\\u5173\\u95ed\",\n",
       "                    \"\\u5237\\u65b0\"\n",
       "                ],\n",
       "                \"backgroundColor\": \"#fff\",\n",
       "                \"textareaColor\": \"#fff\",\n",
       "                \"textareaBorderColor\": \"#333\",\n",
       "                \"textColor\": \"#000\",\n",
       "                \"buttonColor\": \"#c23531\",\n",
       "                \"buttonTextColor\": \"#fff\"\n",
       "            },\n",
       "            \"dataZoom\": {\n",
       "                \"show\": true,\n",
       "                \"title\": {\n",
       "                    \"zoom\": \"\\u533a\\u57df\\u7f29\\u653e\",\n",
       "                    \"back\": \"\\u533a\\u57df\\u7f29\\u653e\\u8fd8\\u539f\"\n",
       "                },\n",
       "                \"icon\": {},\n",
       "                \"filterMode\": \"filter\"\n",
       "            },\n",
       "            \"magicType\": {\n",
       "                \"show\": true,\n",
       "                \"type\": [\n",
       "                    \"line\",\n",
       "                    \"bar\",\n",
       "                    \"stack\",\n",
       "                    \"tiled\"\n",
       "                ],\n",
       "                \"title\": {\n",
       "                    \"line\": \"\\u5207\\u6362\\u4e3a\\u6298\\u7ebf\\u56fe\",\n",
       "                    \"bar\": \"\\u5207\\u6362\\u4e3a\\u67f1\\u72b6\\u56fe\",\n",
       "                    \"stack\": \"\\u5207\\u6362\\u4e3a\\u5806\\u53e0\",\n",
       "                    \"tiled\": \"\\u5207\\u6362\\u4e3a\\u5e73\\u94fa\"\n",
       "                },\n",
       "                \"icon\": {}\n",
       "            }\n",
       "        }\n",
       "    }\n",
       "};\n",
       "        chart_8ac4bf72536f43bea258913573bc2c5d.setOption(option_8ac4bf72536f43bea258913573bc2c5d);\n",
       "    </script>\n",
       "</body>\n",
       "</html>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cjt=yg[yg['支付时间']!='-']\n",
    "\n",
    "cj1=cjt[(cjt['商品发货']=='已发货')&(cjt['商品售后']=='无')]\n",
    "cjw1=cjt[cjt['商品发货']=='未发货']\n",
    "print(yg['商品发货'].value_counts())\n",
    "\n",
    "\n",
    "# 假设 yg 是你的 DataFrame，这里模拟生成示例数据\n",
    "\n",
    "\n",
    "# 筛选已发货和未发货的数据\n",
    "cj1=cjt[(cjt['商品发货']=='已发货')&(cjt['商品售后']=='无')]\n",
    "cjw1=cjt[cjt['商品发货']=='未发货']\n",
    "fhh=cjt[(cjt['商品发货']=='已发货')&(cjt['商品售后']!='无')]\n",
    "# 计算已发货和未发货的数量\n",
    "shipped_count = len(cj1)\n",
    "unshipped_count = len(cjw1)\n",
    "fhh_count = len(fhh)\n",
    "# 计算占比\n",
    "total_count = shipped_count + unshipped_count+fhh_count\n",
    "shipped_ratio = shipped_count / total_count\n",
    "unshipped_ratio = unshipped_count / total_count\n",
    "fhh_ratio=fhh_count/ total_count\n",
    "zttk=(fhh_count+unshipped_count)/(shipped_count+unshipped_count+fhh_count)\n",
    "zttk=\"{:.3f}%\".format(zttk*100)\n",
    "print(f'售前+售后退款率{zttk}')\n",
    "# 准备数据用于绘制饼图\n",
    "labels = ['已发货', '售前退款','售后退款']\n",
    "values = [shipped_ratio, unshipped_ratio,fhh_ratio]\n",
    "\n",
    "# 创建饼图\n",
    "pie = (\n",
    "    Pie()\n",
    "    .add(\n",
    "        series_name=\"商品发货状态占比\",\n",
    "        data_pair=[list(z) for z in zip(labels, values)],\n",
    "        radius=[\"0%\", \"75%\"],\n",
    "    )\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title=\"商品发货状态占比饼图\"),\n",
    "        legend_opts=opts.LegendOpts(orient=\"vertical\", pos_top=\"15%\", pos_left=\"2%\"),\n",
    "        toolbox_opts=opts.ToolboxOpts(is_show=True)\n",
    "    )\n",
    "    .set_series_opts(\n",
    "        label_opts=opts.LabelOpts(formatter=\"{b}: {d}%\")\n",
    "    )\n",
    ")\n",
    "\n",
    "# 渲染图表\n",
    "pie.render_notebook()\n",
    "# 生成 HTML 代码\n",
    "html = pie.render_embed()\n",
    "\n",
    "# 在 Notebook 中显示\n",
    "HTML(html)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "075c8692",
   "metadata": {
    "hide_input": true
   },
   "outputs": [],
   "source": [
    "#成交金额cjje(含发货后退款)--------------------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "id": "de1dc8c9",
   "metadata": {
    "hide_input": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "包含售前售后的金额20095.900\n"
     ]
    }
   ],
   "source": [
    "# cjje=cj[\"商品价格\"].sum()\n",
    "# cjje2=cj2[\"商品价格\"].sum()\n",
    "cjje=\"{:.3f}\".format(cj[\"订单实际支付金额\"].sum())\n",
    "cjje2=\"{:.3f}\".format(cj2[\"订单实际支付金额\"].sum())\n",
    "print(f'包含售前售后的金额{cjje2}')\n",
    "cjje=float(cjje)\n",
    "cjje2=float(cjje2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "49ea966b",
   "metadata": {
    "hide_input": true
   },
   "outputs": [],
   "source": [
    "#cpcb  1.45 一支运费2.5 5支运费按照2.8 平台扣点0.025 运费险 0.4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "id": "814c6271",
   "metadata": {
    "hide_input": true
   },
   "outputs": [],
   "source": [
    "cpcb=cj[\"订单实际支付金额\"].copy()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "id": "a1c53f6b",
   "metadata": {
    "hide_input": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "每个价格的占比\n",
      "39.9    405\n",
      "59.9     17\n",
      "83.9      9\n",
      "69.9      1\n",
      "Name: 订单实际支付金额, dtype: int64\n",
      "平均客单价为: 41.673\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<!DOCTYPE html>\n",
       "<html>\n",
       "<head>\n",
       "    <meta charset=\"UTF-8\">\n",
       "    <title>Awesome-pyecharts</title>\n",
       "                <script type=\"text/javascript\" src=\"https://assets.pyecharts.org/assets/v5/echarts.min.js\"></script>\n",
       "\n",
       "    \n",
       "</head>\n",
       "<body >\n",
       "    <div id=\"448e7192224d45419ff9f0e7a5f34df3\" class=\"chart-container\" style=\"width:900px; height:500px; \"></div>\n",
       "    <script>\n",
       "        var chart_448e7192224d45419ff9f0e7a5f34df3 = echarts.init(\n",
       "            document.getElementById('448e7192224d45419ff9f0e7a5f34df3'), 'white', {renderer: 'canvas'});\n",
       "        var option_448e7192224d45419ff9f0e7a5f34df3 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"aria\": {\n",
       "        \"enabled\": false\n",
       "    },\n",
       "    \"color\": [\n",
       "        \"#5470c6\",\n",
       "        \"#91cc75\",\n",
       "        \"#fac858\",\n",
       "        \"#ee6666\",\n",
       "        \"#73c0de\",\n",
       "        \"#3ba272\",\n",
       "        \"#fc8452\",\n",
       "        \"#9a60b4\",\n",
       "        \"#ea7ccc\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"pie\",\n",
       "            \"name\": \"\\u5546\\u54c1\\u4ef7\\u683c\\u5360\\u6bd4\",\n",
       "            \"colorBy\": \"data\",\n",
       "            \"legendHoverLink\": true,\n",
       "            \"selectedMode\": false,\n",
       "            \"selectedOffset\": 10,\n",
       "            \"clockwise\": true,\n",
       "            \"startAngle\": 90,\n",
       "            \"minAngle\": 0,\n",
       "            \"minShowLabelAngle\": 0,\n",
       "            \"avoidLabelOverlap\": true,\n",
       "            \"stillShowZeroSum\": true,\n",
       "            \"percentPrecision\": 2,\n",
       "            \"showEmptyCircle\": true,\n",
       "            \"emptyCircleStyle\": {\n",
       "                \"color\": \"lightgray\",\n",
       "                \"borderColor\": \"#000\",\n",
       "                \"borderWidth\": 0,\n",
       "                \"borderType\": \"solid\",\n",
       "                \"borderDashOffset\": 0,\n",
       "                \"borderCap\": \"butt\",\n",
       "                \"borderJoin\": \"bevel\",\n",
       "                \"borderMiterLimit\": 10,\n",
       "                \"opacity\": 1\n",
       "            },\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": 39.9,\n",
       "                    \"value\": 405\n",
       "                },\n",
       "                {\n",
       "                    \"name\": 59.9,\n",
       "                    \"value\": 17\n",
       "                },\n",
       "                {\n",
       "                    \"name\": 83.9,\n",
       "                    \"value\": 9\n",
       "                },\n",
       "                {\n",
       "                    \"name\": 69.9,\n",
       "                    \"value\": 1\n",
       "                }\n",
       "            ],\n",
       "            \"radius\": [\n",
       "                \"0%\",\n",
       "                \"60%\"\n",
       "            ],\n",
       "            \"center\": [\n",
       "                \"50%\",\n",
       "                \"50%\"\n",
       "            ],\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"margin\": 8,\n",
       "                \"formatter\": \"{b}: {d}%\",\n",
       "                \"valueAnimation\": false\n",
       "            },\n",
       "            \"labelLine\": {\n",
       "                \"show\": true,\n",
       "                \"showAbove\": false,\n",
       "                \"length\": 15,\n",
       "                \"length2\": 15,\n",
       "                \"smooth\": false,\n",
       "                \"minTurnAngle\": 90,\n",
       "                \"maxSurfaceAngle\": 90\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                39.9,\n",
       "                59.9,\n",
       "                83.9,\n",
       "                69.9\n",
       "            ],\n",
       "            \"selected\": {},\n",
       "            \"show\": true,\n",
       "            \"left\": \"2%\",\n",
       "            \"top\": \"15%\",\n",
       "            \"orient\": \"vertical\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14,\n",
       "            \"backgroundColor\": \"transparent\",\n",
       "            \"borderColor\": \"#ccc\",\n",
       "            \"borderRadius\": 0,\n",
       "            \"pageButtonItemGap\": 5,\n",
       "            \"pageButtonPosition\": \"end\",\n",
       "            \"pageFormatter\": \"{current}/{total}\",\n",
       "            \"pageIconColor\": \"#2f4554\",\n",
       "            \"pageIconInactiveColor\": \"#aaa\",\n",
       "            \"pageIconSize\": 15,\n",
       "            \"animationDurationUpdate\": 800,\n",
       "            \"selector\": false,\n",
       "            \"selectorPosition\": \"auto\",\n",
       "            \"selectorItemGap\": 7,\n",
       "            \"selectorButtonGap\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"enterable\": false,\n",
       "        \"confine\": false,\n",
       "        \"appendToBody\": false,\n",
       "        \"transitionDuration\": 0.4,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5,\n",
       "        \"order\": \"seriesAsc\"\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"text\": \"\\u5546\\u54c1\\u4ef7\\u683c\\u5360\\u6bd4\\u997c\\u56fe\",\n",
       "            \"target\": \"blank\",\n",
       "            \"subtarget\": \"blank\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"textAlign\": \"auto\",\n",
       "            \"textVerticalAlign\": \"auto\",\n",
       "            \"triggerEvent\": false\n",
       "        }\n",
       "    ],\n",
       "    \"toolbox\": {\n",
       "        \"show\": true,\n",
       "        \"orient\": \"horizontal\",\n",
       "        \"itemSize\": 15,\n",
       "        \"itemGap\": 10,\n",
       "        \"left\": \"80%\",\n",
       "        \"feature\": {\n",
       "            \"saveAsImage\": {\n",
       "                \"type\": \"png\",\n",
       "                \"backgroundColor\": \"auto\",\n",
       "                \"connectedBackgroundColor\": \"#fff\",\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u4fdd\\u5b58\\u4e3a\\u56fe\\u7247\",\n",
       "                \"pixelRatio\": 1\n",
       "            },\n",
       "            \"restore\": {\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u8fd8\\u539f\"\n",
       "            },\n",
       "            \"dataView\": {\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u6570\\u636e\\u89c6\\u56fe\",\n",
       "                \"readOnly\": false,\n",
       "                \"lang\": [\n",
       "                    \"\\u6570\\u636e\\u89c6\\u56fe\",\n",
       "                    \"\\u5173\\u95ed\",\n",
       "                    \"\\u5237\\u65b0\"\n",
       "                ],\n",
       "                \"backgroundColor\": \"#fff\",\n",
       "                \"textareaColor\": \"#fff\",\n",
       "                \"textareaBorderColor\": \"#333\",\n",
       "                \"textColor\": \"#000\",\n",
       "                \"buttonColor\": \"#c23531\",\n",
       "                \"buttonTextColor\": \"#fff\"\n",
       "            },\n",
       "            \"dataZoom\": {\n",
       "                \"show\": true,\n",
       "                \"title\": {\n",
       "                    \"zoom\": \"\\u533a\\u57df\\u7f29\\u653e\",\n",
       "                    \"back\": \"\\u533a\\u57df\\u7f29\\u653e\\u8fd8\\u539f\"\n",
       "                },\n",
       "                \"icon\": {},\n",
       "                \"filterMode\": \"filter\"\n",
       "            },\n",
       "            \"magicType\": {\n",
       "                \"show\": true,\n",
       "                \"type\": [\n",
       "                    \"line\",\n",
       "                    \"bar\",\n",
       "                    \"stack\",\n",
       "                    \"tiled\"\n",
       "                ],\n",
       "                \"title\": {\n",
       "                    \"line\": \"\\u5207\\u6362\\u4e3a\\u6298\\u7ebf\\u56fe\",\n",
       "                    \"bar\": \"\\u5207\\u6362\\u4e3a\\u67f1\\u72b6\\u56fe\",\n",
       "                    \"stack\": \"\\u5207\\u6362\\u4e3a\\u5806\\u53e0\",\n",
       "                    \"tiled\": \"\\u5207\\u6362\\u4e3a\\u5e73\\u94fa\"\n",
       "                },\n",
       "                \"icon\": {}\n",
       "            }\n",
       "        }\n",
       "    }\n",
       "};\n",
       "        chart_448e7192224d45419ff9f0e7a5f34df3.setOption(option_448e7192224d45419ff9f0e7a5f34df3);\n",
       "    </script>\n",
       "</body>\n",
       "</html>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Pie\n",
    "\n",
    "# 模拟你提供的 Series 数据\n",
    "data = cpcb\n",
    "series = pd.Series(cpcb, name='订单实际支付金额')\n",
    "\n",
    "# 统计每个价格的数量\n",
    "value_counts = series.value_counts()\n",
    "print(f'每个价格的占比\\n{value_counts}')\n",
    "\n",
    "\n",
    "#1111111111111111\n",
    "total_sales = (value_counts.index * value_counts).sum()\n",
    "\n",
    "# 计算总订单数\n",
    "total_orders = value_counts.sum()\n",
    "\n",
    "# 计算平均客单价\n",
    "average_price = total_sales / total_orders\n",
    "average_price = round(average_price, 3)\n",
    "print(\"平均客单价为:\", average_price)\n",
    "value_counts.index\n",
    "# 提取数据和标签\n",
    "labels = value_counts.index.tolist()\n",
    "values = value_counts.values.tolist()\n",
    "\n",
    "# 创建饼图\n",
    "pie = (\n",
    "    Pie()\n",
    "    .add(\n",
    "        series_name=\"商品价格占比\",\n",
    "        data_pair=[list(z) for z in zip(labels, values)],\n",
    "        radius=[\"0%\", \"60%\"],\n",
    "    )\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title=\"商品价格占比饼图\"),\n",
    "        legend_opts=opts.LegendOpts(orient=\"vertical\", pos_top=\"15%\", pos_left=\"2%\"),\n",
    "        toolbox_opts=opts.ToolboxOpts(is_show=True)\n",
    "    )\n",
    "    .set_series_opts(\n",
    "        label_opts=opts.LabelOpts(formatter=\"{b}: {d}%\")\n",
    "    )\n",
    ")\n",
    "\n",
    "# 渲染图表\n",
    "pie.render_notebook()\n",
    "# 生成 HTML 代码\n",
    "html = pie.render_embed()\n",
    "\n",
    "# 在 Notebook 中显示\n",
    "HTML(html)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "id": "96c0ee46",
   "metadata": {
    "hide_input": true
   },
   "outputs": [],
   "source": [
    "cpcb[cpcb == 39.9]=7+(cpcb[cpcb == 39.9]*0.025)+0.3\n",
    "cpcb[cpcb == 59.9]=9.75+(cpcb[cpcb == 59.9]*0.025)+0.3\n",
    "cpcb[cpcb == 83.9]=12.95+(cpcb[cpcb == 83.9]*0.025)+0.3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "0ada41c9",
   "metadata": {
    "hide_input": true
   },
   "outputs": [],
   "source": [
    "#产品成本加运费包含退货退款的+平台服务费yc-------------\n",
    "yc=\"{:.3f}\".format(cpcb.sum())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "05cdde14",
   "metadata": {},
   "outputs": [],
   "source": [
    "#退款的金额同时减去平台服务费，减去货物成本乘以0.5的破损thb是备份thb  ---------------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "815efd00",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "thb=cj[\"商品已退款金额\"].copy()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "id": "d79088e0",
   "metadata": {},
   "outputs": [],
   "source": [
    "#总的退款金额th1减去了退款金额+上了平台服务费，+上了产品成本*0.5的损耗th1 ---------------------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "id": "4c3eeebf",
   "metadata": {},
   "outputs": [],
   "source": [
    "thb[thb== 39.9]=39.9-(thb[thb == 39.9]*0.025)-(7*0.6)\n",
    "thb[thb == 59.9]=59.9-(thb[thb == 59.9]*0.025)-(9.75*0.6)\n",
    "thb[thb == 83.9]=83.9-(thb[thb == 83.9]*0.025)-(12.95*0.6)\n",
    "th1=thb.sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "id": "5806faba",
   "metadata": {},
   "outputs": [],
   "source": [
    "#总盈利去zyl  cjje发出货的钱  yc产品成本加运费包含退货退款的+平台服务费  xh消耗费用  th1总的退款金额th1减去了退款金额+上了平台服务费，+上了产品成本*0.5的损耗th1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "id": "ad09dbab",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "消耗费用 1000\n"
     ]
    }
   ],
   "source": [
    "xh=float(input('消耗费用'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "id": "f1575dea",
   "metadata": {
    "hide_input": true
   },
   "outputs": [],
   "source": [
    "#zyl=cjje-yc-th1-xh\n",
    "# zyl=cjje-th1-xh\n",
    "# roi=cjje2/xh\n",
    "# zyl=f\"{cjje:.3f}\"\n",
    "# roi=f\"{cjje2/xh:.3f}\"\n",
    "zyl=\"{:.3f}\".format(cjje-th1-xh)\n",
    "roi=\"{:.3f}\".format(cjje2/xh)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "id": "26d74eaf",
   "metadata": {
    "hide_input": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "整体盈亏：16655.775\n",
      "整体ROI：20.096\n"
     ]
    }
   ],
   "source": [
    "print(f'整体盈亏：{zyl}')\n",
    "print(f\"整体ROI：{roi}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "id": "502cebcc",
   "metadata": {
    "hide_input": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<!DOCTYPE html>\n",
       "<html>\n",
       "<head>\n",
       "    <meta charset=\"UTF-8\">\n",
       "    <title>Awesome-pyecharts</title>\n",
       "                <script type=\"text/javascript\" src=\"https://assets.pyecharts.org/assets/v5/echarts.min.js\"></script>\n",
       "\n",
       "    \n",
       "</head>\n",
       "<body >\n",
       "    <div id=\"5ac79dfece8b4bfaa421d262fb6fb667\" class=\"chart-container\" style=\"width:900px; height:500px; \"></div>\n",
       "    <script>\n",
       "        var chart_5ac79dfece8b4bfaa421d262fb6fb667 = echarts.init(\n",
       "            document.getElementById('5ac79dfece8b4bfaa421d262fb6fb667'), 'white', {renderer: 'canvas'});\n",
       "        var option_5ac79dfece8b4bfaa421d262fb6fb667 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"aria\": {\n",
       "        \"enabled\": false\n",
       "    },\n",
       "    \"color\": [\n",
       "        \"#FFA500\",\n",
       "        \"#FF6347\",\n",
       "        \"#32CD32\",\n",
       "        \"#4169E1\",\n",
       "        \"#9370DB\",\n",
       "        \"#5470c6\",\n",
       "        \"#91cc75\",\n",
       "        \"#fac858\",\n",
       "        \"#ee6666\",\n",
       "        \"#73c0de\",\n",
       "        \"#3ba272\",\n",
       "        \"#fc8452\",\n",
       "        \"#9a60b4\",\n",
       "        \"#ea7ccc\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"\\u6210\\u4ea4\\u91d1\\u989d\",\n",
       "            \"legendHoverLink\": true,\n",
       "            \"data\": [\n",
       "                18002.8\n",
       "            ],\n",
       "            \"realtimeSort\": false,\n",
       "            \"showBackground\": false,\n",
       "            \"stackStrategy\": \"samesign\",\n",
       "            \"cursor\": \"pointer\",\n",
       "            \"barMinHeight\": 0,\n",
       "            \"barCategoryGap\": \"20%\",\n",
       "            \"barGap\": \"30%\",\n",
       "            \"large\": false,\n",
       "            \"largeThreshold\": 400,\n",
       "            \"seriesLayoutBy\": \"column\",\n",
       "            \"datasetIndex\": 0,\n",
       "            \"clip\": true,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"inside\",\n",
       "                \"margin\": 8,\n",
       "                \"valueAnimation\": false\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"\\u6210\\u672c\",\n",
       "            \"legendHoverLink\": true,\n",
       "            \"data\": [\n",
       "                \"3764.823\"\n",
       "            ],\n",
       "            \"realtimeSort\": false,\n",
       "            \"showBackground\": false,\n",
       "            \"stack\": \"expenses\",\n",
       "            \"stackStrategy\": \"samesign\",\n",
       "            \"cursor\": \"pointer\",\n",
       "            \"barMinHeight\": 0,\n",
       "            \"barCategoryGap\": \"20%\",\n",
       "            \"barGap\": \"30%\",\n",
       "            \"large\": false,\n",
       "            \"largeThreshold\": 400,\n",
       "            \"seriesLayoutBy\": \"column\",\n",
       "            \"datasetIndex\": 0,\n",
       "            \"clip\": true,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"inside\",\n",
       "                \"margin\": 8,\n",
       "                \"valueAnimation\": false\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"\\u9000\\u8d27\",\n",
       "            \"legendHoverLink\": true,\n",
       "            \"data\": [\n",
       "                347.025\n",
       "            ],\n",
       "            \"realtimeSort\": false,\n",
       "            \"showBackground\": false,\n",
       "            \"stack\": \"expenses\",\n",
       "            \"stackStrategy\": \"samesign\",\n",
       "            \"cursor\": \"pointer\",\n",
       "            \"barMinHeight\": 0,\n",
       "            \"barCategoryGap\": \"20%\",\n",
       "            \"barGap\": \"30%\",\n",
       "            \"large\": false,\n",
       "            \"largeThreshold\": 400,\n",
       "            \"seriesLayoutBy\": \"column\",\n",
       "            \"datasetIndex\": 0,\n",
       "            \"clip\": true,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"inside\",\n",
       "                \"margin\": 8,\n",
       "                \"valueAnimation\": false\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"\\u6295\\u6d41\\u8d39\\u7528\",\n",
       "            \"legendHoverLink\": true,\n",
       "            \"data\": [\n",
       "                1000.0\n",
       "            ],\n",
       "            \"realtimeSort\": false,\n",
       "            \"showBackground\": false,\n",
       "            \"stack\": \"expenses\",\n",
       "            \"stackStrategy\": \"samesign\",\n",
       "            \"cursor\": \"pointer\",\n",
       "            \"barMinHeight\": 0,\n",
       "            \"barCategoryGap\": \"20%\",\n",
       "            \"barGap\": \"30%\",\n",
       "            \"large\": false,\n",
       "            \"largeThreshold\": 400,\n",
       "            \"seriesLayoutBy\": \"column\",\n",
       "            \"datasetIndex\": 0,\n",
       "            \"clip\": true,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"inside\",\n",
       "                \"margin\": 8,\n",
       "                \"valueAnimation\": false\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"\\u76c8\\u5229\\u91d1\\u989d\",\n",
       "            \"legendHoverLink\": true,\n",
       "            \"data\": [\n",
       "                12890.952\n",
       "            ],\n",
       "            \"realtimeSort\": false,\n",
       "            \"showBackground\": false,\n",
       "            \"stackStrategy\": \"samesign\",\n",
       "            \"cursor\": \"pointer\",\n",
       "            \"barMinHeight\": 0,\n",
       "            \"barCategoryGap\": \"20%\",\n",
       "            \"barGap\": \"30%\",\n",
       "            \"large\": false,\n",
       "            \"largeThreshold\": 400,\n",
       "            \"seriesLayoutBy\": \"column\",\n",
       "            \"datasetIndex\": 0,\n",
       "            \"clip\": true,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"inside\",\n",
       "                \"margin\": 8,\n",
       "                \"valueAnimation\": false\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u6210\\u4ea4\\u91d1\\u989d\",\n",
       "                \"\\u6210\\u672c\",\n",
       "                \"\\u9000\\u8d27\",\n",
       "                \"\\u6295\\u6d41\\u8d39\\u7528\",\n",
       "                \"\\u76c8\\u5229\\u91d1\\u989d\"\n",
       "            ],\n",
       "            \"selected\": {},\n",
       "            \"show\": true,\n",
       "            \"top\": \"95%\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14,\n",
       "            \"backgroundColor\": \"transparent\",\n",
       "            \"borderColor\": \"#ccc\",\n",
       "            \"borderRadius\": 0,\n",
       "            \"pageButtonItemGap\": 5,\n",
       "            \"pageButtonPosition\": \"end\",\n",
       "            \"pageFormatter\": \"{current}/{total}\",\n",
       "            \"pageIconColor\": \"#2f4554\",\n",
       "            \"pageIconInactiveColor\": \"#aaa\",\n",
       "            \"pageIconSize\": 15,\n",
       "            \"animationDurationUpdate\": 800,\n",
       "            \"selector\": false,\n",
       "            \"selectorPosition\": \"auto\",\n",
       "            \"selectorItemGap\": 7,\n",
       "            \"selectorButtonGap\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"enterable\": false,\n",
       "        \"confine\": false,\n",
       "        \"appendToBody\": false,\n",
       "        \"transitionDuration\": 0.4,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5,\n",
       "        \"order\": \"seriesAsc\"\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"name\": \"\\u9879\\u76ee\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": true,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"animation\": true,\n",
       "            \"animationThreshold\": 2000,\n",
       "            \"animationDuration\": 1000,\n",
       "            \"animationEasing\": \"cubicOut\",\n",
       "            \"animationDelay\": 0,\n",
       "            \"animationDurationUpdate\": 300,\n",
       "            \"animationEasingUpdate\": \"cubicOut\",\n",
       "            \"animationDelayUpdate\": 0,\n",
       "            \"data\": [\n",
       "                \"\\u6210\\u4ea4\\u91d1\\u989d\",\n",
       "                \"\\u5404\\u9879\\u8d39\\u7528\\u53ca\\u76c8\\u5229\"\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"name\": \"\\u91d1\\u989d\\uff08\\u5143\\uff09\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": true,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"animation\": true,\n",
       "            \"animationThreshold\": 2000,\n",
       "            \"animationDuration\": 1000,\n",
       "            \"animationEasing\": \"cubicOut\",\n",
       "            \"animationDelay\": 0,\n",
       "            \"animationDurationUpdate\": 300,\n",
       "            \"animationEasingUpdate\": \"cubicOut\",\n",
       "            \"animationDelayUpdate\": 0\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"text\": \"\\u76c8\\u5229\\u5206\\u6790\\u67f1\\u72b6\\u56fe\",\n",
       "            \"target\": \"blank\",\n",
       "            \"subtarget\": \"blank\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"textAlign\": \"auto\",\n",
       "            \"textVerticalAlign\": \"auto\",\n",
       "            \"triggerEvent\": false\n",
       "        }\n",
       "    ],\n",
       "    \"toolbox\": {\n",
       "        \"show\": true,\n",
       "        \"orient\": \"horizontal\",\n",
       "        \"itemSize\": 15,\n",
       "        \"itemGap\": 10,\n",
       "        \"left\": \"80%\",\n",
       "        \"feature\": {\n",
       "            \"saveAsImage\": {\n",
       "                \"type\": \"png\",\n",
       "                \"backgroundColor\": \"auto\",\n",
       "                \"connectedBackgroundColor\": \"#fff\",\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u4fdd\\u5b58\\u4e3a\\u56fe\\u7247\",\n",
       "                \"pixelRatio\": 1\n",
       "            },\n",
       "            \"restore\": {\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u8fd8\\u539f\"\n",
       "            },\n",
       "            \"dataView\": {\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u6570\\u636e\\u89c6\\u56fe\",\n",
       "                \"readOnly\": false,\n",
       "                \"lang\": [\n",
       "                    \"\\u6570\\u636e\\u89c6\\u56fe\",\n",
       "                    \"\\u5173\\u95ed\",\n",
       "                    \"\\u5237\\u65b0\"\n",
       "                ],\n",
       "                \"backgroundColor\": \"#fff\",\n",
       "                \"textareaColor\": \"#fff\",\n",
       "                \"textareaBorderColor\": \"#333\",\n",
       "                \"textColor\": \"#000\",\n",
       "                \"buttonColor\": \"#c23531\",\n",
       "                \"buttonTextColor\": \"#fff\"\n",
       "            },\n",
       "            \"dataZoom\": {\n",
       "                \"show\": true,\n",
       "                \"title\": {\n",
       "                    \"zoom\": \"\\u533a\\u57df\\u7f29\\u653e\",\n",
       "                    \"back\": \"\\u533a\\u57df\\u7f29\\u653e\\u8fd8\\u539f\"\n",
       "                },\n",
       "                \"icon\": {},\n",
       "                \"filterMode\": \"filter\"\n",
       "            },\n",
       "            \"magicType\": {\n",
       "                \"show\": true,\n",
       "                \"type\": [\n",
       "                    \"line\",\n",
       "                    \"bar\",\n",
       "                    \"stack\",\n",
       "                    \"tiled\"\n",
       "                ],\n",
       "                \"title\": {\n",
       "                    \"line\": \"\\u5207\\u6362\\u4e3a\\u6298\\u7ebf\\u56fe\",\n",
       "                    \"bar\": \"\\u5207\\u6362\\u4e3a\\u67f1\\u72b6\\u56fe\",\n",
       "                    \"stack\": \"\\u5207\\u6362\\u4e3a\\u5806\\u53e0\",\n",
       "                    \"tiled\": \"\\u5207\\u6362\\u4e3a\\u5e73\\u94fa\"\n",
       "                },\n",
       "                \"icon\": {}\n",
       "            }\n",
       "        }\n",
       "    }\n",
       "};\n",
       "        chart_5ac79dfece8b4bfaa421d262fb6fb667.setOption(option_5ac79dfece8b4bfaa421d262fb6fb667);\n",
       "    </script>\n",
       "</body>\n",
       "</html>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Bar\n",
    "\n",
    "\n",
    "# 计算盈利金额\n",
    "zyl = float(cjje) - float(yc) - float(th1) - float(xh)\n",
    "\n",
    "# 数据标签\n",
    "labels = [\"成交金额\", \"各项费用及盈利\"]\n",
    "\n",
    "# 各项费用数据\n",
    "expense_labels = [\"成本\", \"退货\", \"投流费用\"]\n",
    "expense_values = [yc, th1, xh]\n",
    "expense_colors = [\"#FF6347\", \"#32CD32\", \"#4169E1\"]\n",
    "\n",
    "# 创建柱状图\n",
    "bar = (\n",
    "    Bar()\n",
    "    .add_xaxis(labels)\n",
    "    .add_yaxis(\"成交金额\", [cjje], color=\"#FFA500\")\n",
    "    .add_yaxis(expense_labels[0], [expense_values[0]], stack=\"expenses\", color=expense_colors[0])\n",
    "    .add_yaxis(expense_labels[1], [expense_values[1]], stack=\"expenses\", color=expense_colors[1])\n",
    "    .add_yaxis(expense_labels[2], [expense_values[2]], stack=\"expenses\", color=expense_colors[2])\n",
    "    .add_yaxis(\"盈利金额\", [zyl], color=\"#9370DB\")\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title=\"盈利分析柱状图\"),\n",
    "        toolbox_opts=opts.ToolboxOpts(is_show=True),\n",
    "        xaxis_opts=opts.AxisOpts(name=\"项目\"),\n",
    "        yaxis_opts=opts.AxisOpts(name=\"金额（元）\"),\n",
    "        legend_opts=opts.LegendOpts(pos_top=\"95%\")\n",
    "    )\n",
    "    .set_series_opts(label_opts=opts.LabelOpts(position=\"inside\"))\n",
    ")\n",
    "\n",
    "bar .render_notebook()\n",
    "# 生成 HTML 代码\n",
    "html = bar.render_embed()\n",
    "# 在 Notebook 中显示\n",
    "HTML(html)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d57c7f41-9a14-44d2-aa06-6f1a4ba1745c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a2ee2bcb-6a30-498e-9d1f-9d2e2f7c6221",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "hide_input": false,
  "kernelspec": {
   "display_name": "Python [conda env:base] *",
   "language": "python",
   "name": "conda-base-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.21"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
